<template>
  <div v-loading="loading" style="width:100vw;height:100vh;">
    <van-list class="top-list-content">
      <ul>
        <li
          class="item"
          v-for="item in topList"
          :key="item.id"
          @click="selectItem(item)"
        >
          <van-image width="100px" height="100px" :src="item.pic" />
          <ul class="song-list">
            <li
              class="song"
              v-for="(song, index) in item.songList"
              :key="song.id"
            >
              <span>{{ index + 1 }}. </span>
              <span>{{ song.songName }}-{{ song.singerName }}</span>
            </li>
          </ul>
        </li>
      </ul>
    </van-list>
    <router-view v-slot="{ Component }">
      <transition appear name="slide">
        <component :is="Component" :data="selectedTop" />
      </transition>
    </router-view>
  </div>
</template>

<script>
import { getTopList } from '@/service/top-list'
import { TOP_KEY } from '@/assets/js/constant'
import { setStorage } from '@/utils/storage'

export default {
  name: 'list',
  components: {},
  data() {
    return {
      topList: [],
      loading: true,
      selectedTop: null
    }
  },
  async created() {
    const result = await getTopList()
    console.log(result)
    this.topList = result.topList
    this.loading = false
  },
  methods: {
    selectItem(item) {
      this.selectedTop = item
      this.cacheTop(item)
      this.$router.push({
        name: 'listDetail',
        params: item
      })
    },
    cacheTop(top) {
      setStorage(TOP_KEY, top)
    }
  }
}
</script>

<style lang="scss" scoped>
.top-list-content {
  width: 100vw;
  height: 100%;
  padding: 20px;
  // overflow: hidden;
  .item {
    width: 100%;
    height: 100px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    &:last-child {
      padding-bottom: 20px;
    }
    .van-image {
      flex-shrink: 0;
    }
    .song-list {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 0 20px;
      height: 100px;
      overflow: hidden;
      background: $color-highlight-background;
      color: $color-text-d;
      font-size: $font-size-small;
      .song {
        @include no-wrap();
        line-height: 26px;
      }
    }
  }
}
</style>
